package com.tianbo.elfii.client.common;

import java.io.*;
import java.sql.*;
import java.net.*;
import java.awt.*;
import java.util.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.event.*;
import java.awt.image.*;
import javax.imageio.*;

import com.tianbo.elfii.client.common.ElfiiCommonUtil.FeedBackType;

/**  <pre>
     <b>类功能描述：</b><pre>
     完成 历史查询第3级 功能要求。
     </pre>
     @version 1.0.1
     @author 高伟 
*/

public class ElfiiCommonHistoryResult {

    JButton okButton;
    HistoryResultPanel historyPanel;

    String sqlTrainnerId;
    String sqlTrainningTitle;
    String sqlStartDate;
    String sqlEndDate;
    String sqlStartDateHIJ;
    String sqlEndDateHIJ;
    
    boolean isTrainingD;
    boolean isDrawVisualResult;

    java.util.Vector <ElfiiCommonTypeTopic> exerciseTopics ;    
    java.util.ArrayList exerciseIdInfoList; 
    int viewExerciseIdIndex;  

    JFrame mainFrame;
    ElfiiCommonRunInfo runInfo;
    
    ImageIcon visualSelectedIcon;
    ImageIcon hearSelectedIcon;
    
    JButton exchangeBtn;
    
    public void setRunInfo(ElfiiCommonRunInfo runInfo){
        this.runInfo=runInfo;
        this.mainFrame=runInfo.getMainFrame();
    }

    class ExerciseIdInfo {
        String gameTitle;
        int trainningItemLevel;
        String trainningTitle;
        String startDate;
        String startTime;
        String exerciseId; //数据库的内容
        String allAvg="空";
        String allAvgSection_1="空_1";
        String allAvgSection_2="空_1";
        String allAvgSection_3="空_1";
        BufferedImage capturedTrainningResultImage;
        int historyCorrectRate;
        int historyCompletedRate;
        int correctRate;
        int completedRate;
        int bz;
    }

    public void setSqlItems(String sqlTrainnerId,String sqlTrainningTitle,String sqlStartDate,String sqlEndDate){
        this.sqlTrainnerId=sqlTrainnerId;
        this.sqlTrainningTitle=sqlTrainningTitle;
        this.sqlStartDate=sqlStartDate;
        this.sqlEndDate=sqlEndDate;
    }

    public void dealBackButton(){
        mainFrame.getContentPane().removeAll();
        ElfiiCommonHistoryItem historyItem = new ElfiiCommonHistoryItem();
        historyItem.setRunInfo(runInfo);
        historyItem.setSqlItems(sqlTrainnerId,sqlStartDate,sqlEndDate);

        JPanel p=historyItem.createViewPanel();
        mainFrame.getContentPane().setLayout(new BorderLayout());
        mainFrame.getContentPane().add(p,BorderLayout.CENTER);
        mainFrame.validate();
    }

    class HistoryResultPanel extends JPanel {

        public HistoryResultPanel() {
        }
    
        public void paintComponent(Graphics g) {
            super.paintComponent(g);

            Graphics2D g2 = (Graphics2D) g ;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 
		    g2.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);


            g2.setColor(Color.black);
            java.util.Vector <ElfiiCommonTypeTopic> viewTopics = new java.util.Vector <ElfiiCommonTypeTopic>();    

            ElfiiCommonTypeTopic tmpTopic;
            ExerciseIdInfo exerciseIdInfo=(ExerciseIdInfo)exerciseIdInfoList.get(viewExerciseIdIndex);

            for (int i=0; i<exerciseTopics.size(); i++){
                tmpTopic=exerciseTopics.get(i);
                if (tmpTopic.exerciseId.equals(exerciseIdInfo.exerciseId) ){
                    viewTopics.add(tmpTopic);
                }
            }

            exerciseIdInfo.startDate=exerciseIdInfo.startDate.replaceAll("-","");
            exerciseIdInfo.startTime=exerciseIdInfo.startTime.replaceAll("-","");
            exerciseIdInfo.startTime=exerciseIdInfo.startTime.replaceAll(":","");
            exerciseIdInfo.startDate=exerciseIdInfo.startDate+"        "; //-否则位数不够会异常
            exerciseIdInfo.startTime=exerciseIdInfo.startTime+"        ";

            String dateStr=exerciseIdInfo.startDate.substring(0,4)+"/"+exerciseIdInfo.startDate.substring(4,6)+"/"+exerciseIdInfo.startDate.substring(6,8);
            String timeStr=exerciseIdInfo.startTime.substring(0,2)+":"+exerciseIdInfo.startTime.substring(2,4);

            if (exerciseIdInfo.capturedTrainningResultImage==null){
                ElfiiCommonHistoryTypeInfo info = new ElfiiCommonHistoryTypeInfo();
                info.allAvg=exerciseIdInfo.allAvg;
                info.allAvgSection_1=exerciseIdInfo.allAvgSection_1;
                info.allAvgSection_2=exerciseIdInfo.allAvgSection_2;
                info.allAvgSection_3=exerciseIdInfo.allAvgSection_3;
                
                if(isTrainingD){
                	//显示训练D结果时，数据库中的两组结果视为实际的一组结果，故结果数为总数/2
                	info.infoStr="当前页："+(viewExerciseIdIndex/2+1)+"/"+exerciseIdInfoList.size()/2+"   ，难度："+exerciseIdInfo.trainningItemLevel+"  ，训练时间： "+dateStr+" "+timeStr+"";
                }
                else{
                	info.infoStr="当前页："+(viewExerciseIdIndex+1)+"/"+exerciseIdInfoList.size()+"   ，难度："+exerciseIdInfo.trainningItemLevel+"  ，训练时间： "+dateStr+" "+timeStr+"";
                }
                
                info.trainningTitle=exerciseIdInfo.trainningTitle;
                info.trainningCategory=ElfiiCommonUtil.getTrainningCategory(exerciseIdInfo.trainningTitle);

                ElfiiCommonUtil.drawGraphicResult(0,g,viewTopics,info);
            }

            if (exerciseIdInfo.capturedTrainningResultImage!=null){
                if (exerciseIdInfo.trainningTitle.startsWith("L")){
                    g2.drawImage(exerciseIdInfo.capturedTrainningResultImage,null,10,0);
                    String str;
                    g2.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,26));
                    //测试观察效果用
                    //exerciseIdInfo.historyCompletedRate=80;
                    //exerciseIdInfo.historyCorrectRate=30;
                    g2.setColor(ElfiiCommonConstant.Elfii_Blue);
                    str="本次完成率"+exerciseIdInfo.completedRate+"% , 历史平均"+exerciseIdInfo.historyCompletedRate+"%";
                    str+="    本次准确率"+exerciseIdInfo.correctRate+"% , 历史平均"+exerciseIdInfo.historyCorrectRate+"%";
                    int strLen=g.getFontMetrics().stringWidth(str);
                    g2.drawString(str,512-strLen/2,500);

                }
                if (exerciseIdInfo.trainningTitle.startsWith("M")){
                    g2.scale(0.8f,0.8f); 
                    g2.drawImage(exerciseIdInfo.capturedTrainningResultImage,null,200,70);
                    g2.scale(1.25f,1.25f); 
                }
                if (exerciseIdInfo.trainningTitle.startsWith("N")){
                    g2.scale(0.8f,0.8f); 
                    g2.drawImage(exerciseIdInfo.capturedTrainningResultImage,null,200,70);
                    g2.scale(1.25f,1.25f); 
                }

                g2.setColor(Color.white);

                ElfiiCommonHistoryTypeInfo info = new ElfiiCommonHistoryTypeInfo();
                info.trainningTitle=exerciseIdInfo.trainningTitle;
                info.trainningCategory=ElfiiCommonUtil.getTrainningCategory(exerciseIdInfo.trainningTitle);
                g2.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.BOLD,30));
                String str=info.trainningCategory+" ("+info.trainningTitle+")";
                int strLen=g.getFontMetrics().stringWidth(str);
                g2.drawString(str,512-strLen/2,35);

                info.infoStr="当前页："+(viewExerciseIdIndex+1)+"/"+exerciseIdInfoList.size()+"   ，难度："+exerciseIdInfo.trainningItemLevel+"  ，训练时间： "+dateStr+" "+timeStr+"";
                g2.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,26));
                strLen=g.getFontMetrics().stringWidth(info.infoStr);
                g2.drawString(info.infoStr,512-strLen/2,550);


            }
            //-以下内容可以方便地查看每个按钮的坐标是否正确;
            //testXY();
        }
        public Dimension getPreferredSize() {
            return (new Dimension(832,537));
        }
    }

    public void dealPreButton(){
    	
    	int step = 1;
    	
    	if(isTrainingD){
    		step = 2; //训练D中数据库中两组数据实为一组结果数据，故每次翻页要跳跃两组数据
    	}

        viewExerciseIdIndex-=step;
        if (viewExerciseIdIndex<0){
            viewExerciseIdIndex+=step;
    	}
        else{
        	ElfiiCommonUtil.playFeedbackAudio(FeedBackType.CLICK);
        }
        
        historyPanel.repaint();
    }

    public void dealNextButton(){
    	int step = 1;
    	
    	if(isTrainingD){
    		step = 2;//训练D中数据库中两组数据实为一组结果数据，故每次翻页要跳跃两组数据
    	}
    	
        viewExerciseIdIndex+=step;
       
        if (viewExerciseIdIndex>=exerciseIdInfoList.size()){
            viewExerciseIdIndex-=step;
        }
        else{
        	ElfiiCommonUtil.playFeedbackAudio(FeedBackType.CLICK);
        }
        
        historyPanel.repaint();
    }

    public void createHistoryResultPanel(){
        historyPanel=new HistoryResultPanel();
        historyPanel.setLayout(new BorderLayout());
        historyPanel.setBackground(Color.black);
    }

    public JPanel createViewPanel(){
        calcHistoryData();

        JPanel p = new JPanel(new BorderLayout()) ;

        JButton backButton=new JButton();
        backButton.addActionListener( new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                	ElfiiCommonUtil.playFeedbackAudio(FeedBackType.CLICK);
                    dealBackButton();
                }
            });

        JButton preButton=new JButton();
        ImageIcon preIcon = new ImageIcon("resource-common/images/history/syb_01.png","");
        preButton.setIcon(preIcon);
        preButton.addActionListener( new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    dealPreButton();
                }
            });
        JButton nextButton=new JButton();
        ImageIcon nextIcon = new ImageIcon("resource-common/images/history/xyb_01.png","");
        nextButton.setIcon(nextIcon);

        nextButton.addActionListener( new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    dealNextButton();
                }
            });

        String dateStr=sqlStartDate.substring(0,4)+"/"+sqlStartDate.substring(4,6)+"/"+sqlStartDate.substring(6,8);
        JButton homeButton=runInfo.createHomeButton();
        JPanel topPanel=ElfiiCommonUtil.createTopPanel(sqlTrainnerId+"  "+dateStr,backButton,homeButton);
        JPanel bottomPanel=ElfiiCommonUtil.createBottomPanelTwoButton(preButton,nextButton);
        createHistoryResultPanel();
        p.setLayout(null);
        p.setBackground(Color.black);
        p.add(topPanel);
        topPanel.setBounds(0,0,1024,100);
        p.add(bottomPanel);
        bottomPanel.setBounds(0,668,1024,100);
        p.add(historyPanel);
        historyPanel.setBounds(0,101,1000,560);
        
        
        if(isTrainingD){ //查看训练D的数据时，增加一个切换按钮来切换视觉和听觉部分的结果
        	
	        isDrawVisualResult = true; //默认显示视觉的结果
	        
	        visualSelectedIcon = new ImageIcon("resource-common/images/history/visualSelected.png");
	        hearSelectedIcon = new ImageIcon("resource-common/images/history/hearSelected.png");
	        
	        exchangeBtn = new JButton(); //添加视觉和听觉结果切换按钮
	        
	        exchangeBtn.setIcon(visualSelectedIcon);
	        exchangeBtn.setContentAreaFilled(false);
	        exchangeBtn.setFocusPainted(false);
	        exchangeBtn.setBorder(null);
	
	        historyPanel.setLayout(null);
	        historyPanel.add(exchangeBtn);
	        exchangeBtn.setBounds(870, 20, 130, 40);
	        
	        
	        exchangeBtn.addActionListener(new ActionListener(){
	
				@Override
				public void actionPerformed(ActionEvent e) {
					// TODO Auto-generated method stub
					/*训练D先将听觉的结果写入数据库，再写入视觉结果
					 *故在按时间排序后，先读入的是视觉结果
					 *故每一页读入两组结果，第一组为视觉结果，第二组为听觉结果
					 */
					ElfiiCommonUtil.playFeedbackAudio(FeedBackType.CLICK);
					
					if(isDrawVisualResult){//切换为听觉结果
						viewExerciseIdIndex++; 
						isDrawVisualResult = false;
						exchangeBtn.setIcon(hearSelectedIcon);
						
					}
					else{//切换为视觉结果
						viewExerciseIdIndex--;
						isDrawVisualResult = true;
						exchangeBtn.setIcon(visualSelectedIcon);
					}
			        exchangeBtn.setContentAreaFilled(false);
			        exchangeBtn.setBorder(null);
					historyPanel.repaint();
				}
	        	
	        });
        }
        
        return p;
    }
    
    public void calcHistoryData_ABC(){
        Statement st,st2 ;
        ResultSet rs,rs2 ;
        String str="";
        exerciseTopics = new java.util.Vector <ElfiiCommonTypeTopic>();    
        exerciseIdInfoList = new java.util.ArrayList<ExerciseIdInfo>(); 
        
        viewExerciseIdIndex=0;
        try {
            long startTimeMillis=System.currentTimeMillis();
            st = runInfo.getStatement1();

            st2 = runInfo.getStatement2();

            str="select a.trainningTitle,a.trainningItemLevel,a.trainningDate,a.trainningTime,b.id_TrainningItemAPO as exerciseId, actionResult ,section from TrainningItemAPO a,TrainningItemAProduceTopicPO b where a.id=b.id_TrainningItemAPO and a.trainnerId='"+sqlTrainnerId+"' and trainningDate>='"+sqlStartDate+"' and trainningDate<='"+sqlEndDate+"' and trainningTitle='"+sqlTrainningTitle+"' order by b.id_TrainningItemAPO desc,b.id " ;
            rs=st.executeQuery(str);
            String idStr,titleStr,numberStr;
            ElfiiCommonTypeTopic tmpTopic;
            String tmpId="-1";
            ExerciseIdInfo tmpExerciseIdInfo;
            while(rs.next()){
                tmpTopic=new ElfiiCommonTypeTopic();
                tmpTopic.exerciseId=rs.getString("exerciseId");
                tmpTopic.actionResult=rs.getInt("actionResult");
                tmpTopic.section=rs.getInt("section");
                exerciseTopics.add(tmpTopic); 
                if (tmpId.equals(tmpTopic.exerciseId)==false) {
                    tmpId=tmpTopic.exerciseId;
                    tmpExerciseIdInfo = new ExerciseIdInfo();
                    tmpExerciseIdInfo.trainningTitle=rs.getString("trainningTitle");
                    tmpExerciseIdInfo.trainningItemLevel=rs.getInt("trainningItemLevel");
                    tmpExerciseIdInfo.startDate=rs.getString("trainningDate");
                    tmpExerciseIdInfo.startTime=rs.getString("trainningTime");
                    tmpExerciseIdInfo.exerciseId=tmpId;
                    exerciseIdInfoList.add(tmpExerciseIdInfo); 
                }
            }

            for (int i=0; i<exerciseIdInfoList.size(); i++){
                tmpExerciseIdInfo=(ExerciseIdInfo)exerciseIdInfoList.get(i);

                str="select id,trainningTitle,trainningItemLevel from TrainningItemAPO where trainnerId='"+sqlTrainnerId+"' and trainningTitle='"+sqlTrainningTitle+"' and id<='"+tmpExerciseIdInfo.exerciseId+"' limit 10 " ;

                rs=st.executeQuery(str);
                String idList="";
                while (rs.next()){
                    idList=idList+","+rs.getInt("id");
                }
                if (idList.length()>0)
                    idList=idList.substring(1,idList.length());

                str="select a.trainningTitle,a.trainningItemLevel,b.section,b.actionResult,b.id_TrainningItemAPO as exerciseId, actionResult ,section from TrainningItemAPO a,TrainningItemAProduceTopicPO b where a.id=b.id_TrainningItemAPO and a.id in ("+idList+") order by b.id_TrainningItemAPO " ;

                rs=st.executeQuery(str);

                int a,b;
                int allSection=0,allOkSection=0;
                int allSection_1=0,allSection_2=0,allSection_3=0;
                int allOkSection_1=0,allOkSection_2=0,allOkSection_3=0;
                
                while (rs.next()){
                    a=rs.getInt("section");
                    b=rs.getInt("actionResult");
                    allSection++;
                    if (b==ElfiiCommonConstant.React_Ok)
                        allOkSection++;
                    if (a==ElfiiCommonConstant.Section_1){
                        allSection_1++;
                        if (b==ElfiiCommonConstant.React_Ok)
                            allOkSection_1++;
                    }
                    if (a==ElfiiCommonConstant.Section_2){
                        allSection_2++;
                        if (b==ElfiiCommonConstant.React_Ok)
                            allOkSection_2++;
                    }
                    if (a==ElfiiCommonConstant.Section_3){
                        allSection_3++;
                        if (b==ElfiiCommonConstant.React_Ok)
                            allOkSection_3++;
                    }
                }

                str="0.0";
                if (allOkSection>0){
                    double d=100.0*allOkSection/allSection;
                    str=""+(d+0.05);
                    if (str.length()-str.indexOf(".")>1)
                        str=str.substring(0,str.indexOf(".")+2);
                }
                tmpExerciseIdInfo.allAvg=str+"%";

                str="0.0";
                if (allOkSection_1>0){
                    double d=100.0*allOkSection_1/allSection_1;
                    str=""+(d+0.05);
                    if (str.length()-str.indexOf(".")>1)
                        str=str.substring(0,str.indexOf(".")+2);
                }
                tmpExerciseIdInfo.allAvgSection_1=str+"%";

                str="0.0";
                if (allOkSection_2>0){
                    double d=100.0*allOkSection_2/allSection_2;
                    str=""+(d+0.05);
                    if (str.length()-str.indexOf(".")>1)
                        str=str.substring(0,str.indexOf(".")+2);
                }
                tmpExerciseIdInfo.allAvgSection_2=str+"%";

                str="0.0";
                if (allOkSection_3>0){
                    double d=100.0*allOkSection_3/allSection_3;
                    str=""+(d+0.05);
                    if (str.length()-str.indexOf(".")>1)
                        str=str.substring(0,str.indexOf(".")+2);
                }
                tmpExerciseIdInfo.allAvgSection_3=str+"%";
            }


            long endTimeMillis=System.currentTimeMillis();
            //System.out.println("历史查询训练成绩OK，Time:(1/1000) "+(endTimeMillis-startTimeMillis));
        } catch (Exception e) {System.out.print("ElfiiCommonhistoryItem.calcHistoryData() "+e+" "+str);}
    }

    public void calcHistoryData_D(){
        Statement st,st2 ;
        ResultSet rs,rs2 ;
        String str="";
        exerciseTopics = new java.util.Vector <ElfiiCommonTypeTopic>();    
        exerciseIdInfoList = new java.util.ArrayList<ExerciseIdInfo>() ; 
        viewExerciseIdIndex=0;
        try {
            long startTimeMillis=System.currentTimeMillis();
            st = runInfo.getStatement1();

            st2 = runInfo.getStatement2();

            str="select a.trainningTitle,a.trainningItemLevel,a.trainningDate,a.trainningTime,a.bz,b.id_TrainningItemAPO as exerciseId, actionResult ,section from TrainningItemAPO a,TrainningItemAProduceTopicPO b where a.id=b.id_TrainningItemAPO and a.trainnerId='"+sqlTrainnerId+"' and trainningDate>='"+sqlStartDate+"' and trainningDate<='"+sqlEndDate+"' and trainningTitle='"+sqlTrainningTitle+"' order by b.id_TrainningItemAPO desc,b.id " ;
            rs=st.executeQuery(str);
            String idStr,titleStr,numberStr;
            ElfiiCommonTypeTopic tmpTopic;
            String tmpId="-1";
            ExerciseIdInfo tmpExerciseIdInfo;
            while(rs.next()){
                tmpTopic=new ElfiiCommonTypeTopic();
                tmpTopic.exerciseId=rs.getString("exerciseId");
                tmpTopic.actionResult=rs.getInt("actionResult");
                tmpTopic.section=rs.getInt("section");
                exerciseTopics.add(tmpTopic); 
                if (tmpId.equals(tmpTopic.exerciseId)==false) {
                    tmpId=tmpTopic.exerciseId;
                    tmpExerciseIdInfo = new ExerciseIdInfo();
                    tmpExerciseIdInfo.trainningTitle=rs.getString("trainningTitle");
                    tmpExerciseIdInfo.trainningItemLevel=rs.getInt("trainningItemLevel");
                    tmpExerciseIdInfo.startDate=rs.getString("trainningDate");
                    tmpExerciseIdInfo.startTime=rs.getString("trainningTime");
                    tmpExerciseIdInfo.exerciseId=tmpId;
                    tmpExerciseIdInfo.bz=rs.getInt("bz");
                    exerciseIdInfoList.add(tmpExerciseIdInfo); 
                }
            }

            for (int i=0; i<exerciseIdInfoList.size(); i++){
                tmpExerciseIdInfo=(ExerciseIdInfo)exerciseIdInfoList.get(i);

                str="select id,trainningTitle,trainningItemLevel from TrainningItemAPO where trainnerId='"+sqlTrainnerId+"' and trainningTitle='"+sqlTrainningTitle+"' and bz='"+tmpExerciseIdInfo.bz+"' and id<='"+tmpExerciseIdInfo.exerciseId+"' limit 10 " ;

                rs=st.executeQuery(str);
                String idList="";
                while (rs.next()){
                    idList=idList+","+rs.getInt("id");
                }
                if (idList.length()>0)
                    idList=idList.substring(1,idList.length());

                str="select a.trainningTitle,a.trainningItemLevel,b.section,b.actionResult,b.id_TrainningItemAPO as exerciseId, actionResult ,section from TrainningItemAPO a,TrainningItemAProduceTopicPO b where a.id=b.id_TrainningItemAPO and a.id in ("+idList+") order by b.id_TrainningItemAPO " ;
                //System.out.println("======"+str);
                rs=st.executeQuery(str);

                int a,b;
                int allSection=0,allOkSection=0;
                int allSection_1=0,allSection_2=0,allSection_3=0;
                int allOkSection_1=0,allOkSection_2=0,allOkSection_3=0;
                while (rs.next()){
                    a=rs.getInt("section");
                    b=rs.getInt("actionResult");
                    allSection++;
                    if (b==ElfiiCommonConstant.React_Ok)
                        allOkSection++;
                    if (a==ElfiiCommonConstant.Section_1){
                        allSection_1++;
                        if (b==ElfiiCommonConstant.React_Ok)
                            allOkSection_1++;
                    }
                    if (a==ElfiiCommonConstant.Section_2){
                        allSection_2++;
                        if (b==ElfiiCommonConstant.React_Ok)
                            allOkSection_2++;
                    }
                    if (a==ElfiiCommonConstant.Section_3){
                        allSection_3++;
                        if (b==ElfiiCommonConstant.React_Ok)
                            allOkSection_3++;
                    }
                }

//                System.out.println("======sec_1 "+allOkSection_1+"  "+allSection_1);

                str="0.0";
                if (allOkSection>0){
                    double d=100.0*allOkSection/allSection;
                    str=""+(d+0.05);
                    if (str.length()-str.indexOf(".")>1)
                        str=str.substring(0,str.indexOf(".")+2);
                }
                tmpExerciseIdInfo.allAvg=str+"%";

                str="0.0";
                if (allOkSection_1>0){
                    double d=100.0*allOkSection_1/allSection_1;
                    str=""+(d+0.05);
                    if (str.length()-str.indexOf(".")>1)
                        str=str.substring(0,str.indexOf(".")+2);
                }
                tmpExerciseIdInfo.allAvgSection_1=str+"%";

                str="0.0";
                if (allOkSection_2>0){
                    double d=100.0*allOkSection_2/allSection_2;
                    str=""+(d+0.05);
                    if (str.length()-str.indexOf(".")>1)
                        str=str.substring(0,str.indexOf(".")+2);
                }
                tmpExerciseIdInfo.allAvgSection_2=str+"%";

                str="0.0";
                if (allOkSection_3>0){
                    double d=100.0*allOkSection_3/allSection_3;
                    str=""+(d+0.05);
                    if (str.length()-str.indexOf(".")>1)
                        str=str.substring(0,str.indexOf(".")+2);
                }
                tmpExerciseIdInfo.allAvgSection_3=str+"%";
            }


            long endTimeMillis=System.currentTimeMillis();
            //System.out.println("历史查询训练成绩OK，Time:(1/1000) "+(endTimeMillis-startTimeMillis));
        } catch (Exception e) {System.out.print("ElfiiCommonhistoryItem.calcHistoryData() "+e+" "+str);}
    }

    
    
    public void calcHistoryData_FG(){
        Statement st ;
        ResultSet rs ;
        String str="";
        exerciseTopics = new java.util.Vector <ElfiiCommonTypeTopic>();    
        exerciseIdInfoList = new java.util.ArrayList<ExerciseIdInfo>() ; 
        viewExerciseIdIndex=0;
        try {
            long startTimeMillis=System.currentTimeMillis();
            st = runInfo.getStatement1();

            str="select trainningTitle,a.trainningItemLevel,a.trainningDate,a.trainningTime,b.id_BaseTrainningItemPO as exerciseId, perTestTopicResultState as actionResult ,whichPartIndex as section from trainningitemfpo a,trainningitemftesttopicresultpo b where a.id=b.id_BaseTrainningItemPO and a.id_TrainnerInfoPO='"+sqlTrainnerId+"' and trainningDate>='"+sqlStartDateHIJ+"' and trainningDate<='"+sqlEndDateHIJ+"' and trainningTitle='"+sqlTrainningTitle+"' order by b.id_BaseTrainningItemPO desc,b.id " ;

            rs=st.executeQuery(str);

            String idStr,titleStr,numberStr;
            ElfiiCommonTypeTopic tmpTopic;
            String tmpId="-1";
            ExerciseIdInfo tmpExerciseIdInfo;
            while(rs.next()){

                tmpTopic=new ElfiiCommonTypeTopic();
                tmpTopic.exerciseId=rs.getString("exerciseId");
                tmpTopic.actionResult=rs.getInt("actionResult");

                if (tmpTopic.actionResult==ElfiiCommonConstant.React_Ok_FG)
                    tmpTopic.actionResult=ElfiiCommonConstant.React_Ok;
                else
                    tmpTopic.actionResult=ElfiiCommonConstant.React_Wrong;

                tmpTopic.section=rs.getInt("section");
                exerciseTopics.add(tmpTopic); 
                if (tmpId.equals(tmpTopic.exerciseId)==false) {
                    tmpId=tmpTopic.exerciseId;
                    tmpExerciseIdInfo = new ExerciseIdInfo();
                    tmpExerciseIdInfo.trainningTitle=rs.getString("trainningTitle");
                    tmpExerciseIdInfo.trainningItemLevel=rs.getInt("trainningItemLevel");
                    tmpExerciseIdInfo.startDate=rs.getString("trainningDate");
                    tmpExerciseIdInfo.startTime=rs.getString("trainningTime");
                    tmpExerciseIdInfo.exerciseId=tmpId;
                    exerciseIdInfoList.add(tmpExerciseIdInfo); 
                }
            }

            for (int i=0; i<exerciseIdInfoList.size(); i++){
                tmpExerciseIdInfo=(ExerciseIdInfo)exerciseIdInfoList.get(i);
                //System.out.println("======"+tmpExerciseIdInfo.trainningTitle); 
                //System.out.println("======"+tmpExerciseIdInfo.exerciseId); 

                str="select id,trainningTitle,trainningItemLevel from trainningitemfpo where id_TrainnerInfoPO='"+sqlTrainnerId+"' and trainningTitle ='"+sqlTrainningTitle+"' and id<='"+tmpExerciseIdInfo.exerciseId+"' limit 10 " ;

                rs=st.executeQuery(str);

                String idList="";
                while (rs.next()){
                    idList=idList+",'"+rs.getString("id")+"'";
                }
                if (idList.length()>0)
                    idList=idList.substring(1,idList.length());

                str="select trainningTitle,a.trainningItemLevel,b.whichPartIndex as section,b.perTestTopicResultState as actionResult,b.id_BaseTrainningItemPO as exerciseId from trainningitemfpo a,trainningitemftesttopicresultpo b where a.id=b.id_BaseTrainningItemPO and a.id in ("+idList+") order by b.id_BaseTrainningItemPO,b.whichPartIndex " ;

                //System.out.println("======"+str);

                rs=st.executeQuery(str);

                int a,b;
                int allSection=0,allOkSection=0;
                int allSection_1=0,allSection_2=0,allSection_3=0;
                int allOkSection_1=0,allOkSection_2=0,allOkSection_3=0;
                while (rs.next()){
                    a=rs.getInt("section");
                    b=rs.getInt("actionResult");
                    allSection++;
                    if (b==ElfiiCommonConstant.React_Ok_FG)
                        allOkSection++;
                    if (a==ElfiiCommonConstant.Section_1){
                        allSection_1++;
                        if (b==ElfiiCommonConstant.React_Ok_FG)
                            allOkSection_1++;
                    }
                    if (a==ElfiiCommonConstant.Section_2){
                        allSection_2++;
                        if (b==ElfiiCommonConstant.React_Ok_FG)
                            allOkSection_2++;
                    }
                    if (a==ElfiiCommonConstant.Section_3){
                        allSection_3++;
                        if (b==ElfiiCommonConstant.React_Ok_FG)
                            allOkSection_3++;
                    }
                }

                //System.out.println("======sec_1 "+allOkSection_1+"  "+allSection_1);

                str="0.0";
                if (allOkSection>0){
                    double d=100.0*allOkSection/allSection;
                    str=""+(d+0.05);
                    if (str.length()-str.indexOf(".")>1)
                        str=str.substring(0,str.indexOf(".")+2);
                }
                tmpExerciseIdInfo.allAvg=str+"%";

                str="0.0";
                if (allOkSection_1>0){
                    double d=100.0*allOkSection_1/allSection_1;
                    str=""+(d+0.05);
                    if (str.length()-str.indexOf(".")>1)
                        str=str.substring(0,str.indexOf(".")+2);
                }
                tmpExerciseIdInfo.allAvgSection_1=str+"%";

                str="0.0";
                if (allOkSection_2>0){
                    double d=100.0*allOkSection_2/allSection_2;
                    str=""+(d+0.05);
                    if (str.length()-str.indexOf(".")>1)
                        str=str.substring(0,str.indexOf(".")+2);
                }
                tmpExerciseIdInfo.allAvgSection_2=str+"%";

                str="0.0";
                if (allOkSection_3>0){
                    double d=100.0*allOkSection_3/allSection_3;
                    str=""+(d+0.05);
                    if (str.length()-str.indexOf(".")>1)
                        str=str.substring(0,str.indexOf(".")+2);
                }
                tmpExerciseIdInfo.allAvgSection_3=str+"%";
            }

            long endTimeMillis=System.currentTimeMillis();
            //System.out.println("历史查询训练成绩OK，Time:(1/1000) "+(endTimeMillis-startTimeMillis));
        } catch (Exception e) {System.out.print("ElfiiCommonhistoryItem.calcHistoryData() "+e+" "+str);}
    }

    public void calcHistoryData_HIJ(){
        Statement st ;
        ResultSet rs ;
        String str="";
        exerciseTopics = new java.util.Vector <ElfiiCommonTypeTopic>();    
        exerciseIdInfoList = new java.util.ArrayList<ExerciseIdInfo>() ; 
        viewExerciseIdIndex=0;
        try {
            long startTimeMillis=System.currentTimeMillis();
            st = runInfo.getStatement1();

            str="select trainningTitle,a.trainningItemLevel,a.trainningDate,a.trainningTime,b.id_BaseTrainningItemPO as exerciseId, perTestTopicResultState as actionResult ,whichPartIndex as section from trainningitemhpo a,trainningitemhtesttopicresultpo b where a.id=b.id_BaseTrainningItemPO and a.id_TrainnerInfoPO='"+sqlTrainnerId+"' and trainningDate>='"+sqlStartDateHIJ+"' and trainningDate<='"+sqlEndDateHIJ+"' and trainningTitle='"+sqlTrainningTitle+"' order by b.id_BaseTrainningItemPO desc,whichPartIndex,b.id " ;

            rs=st.executeQuery(str);

            String idStr,titleStr,numberStr;
            ElfiiCommonTypeTopic tmpTopic;
            String tmpId="-1";
            ExerciseIdInfo tmpExerciseIdInfo;
            while(rs.next()){
                tmpTopic=new ElfiiCommonTypeTopic();
                tmpTopic.exerciseId=rs.getString("exerciseId");
                tmpTopic.actionResult=rs.getInt("actionResult");
                tmpTopic.section=rs.getInt("section");
                if (tmpTopic.actionResult==ElfiiCommonConstant.React_Ok_HIJ)
                    tmpTopic.actionResult=ElfiiCommonConstant.React_Ok;
                else
                    tmpTopic.actionResult=ElfiiCommonConstant.React_Wrong;
                exerciseTopics.add(tmpTopic); 
                if (tmpId.equals(tmpTopic.exerciseId)==false) {
                    tmpId=tmpTopic.exerciseId;
                    tmpExerciseIdInfo = new ExerciseIdInfo();
                    tmpExerciseIdInfo.trainningTitle=rs.getString("trainningTitle");
                    tmpExerciseIdInfo.trainningItemLevel=rs.getInt("trainningItemLevel");
                    tmpExerciseIdInfo.startDate=rs.getString("trainningDate");
                    tmpExerciseIdInfo.startTime=rs.getString("trainningTime");
                    tmpExerciseIdInfo.exerciseId=tmpId;
                    exerciseIdInfoList.add(tmpExerciseIdInfo); 
                }
            }

            for (int i=0; i<exerciseIdInfoList.size(); i++){
                tmpExerciseIdInfo=(ExerciseIdInfo)exerciseIdInfoList.get(i);
                //System.out.println("======"+tmpExerciseIdInfo.trainningTitle); 
                //System.out.println("======"+tmpExerciseIdInfo.exerciseId); 

                str="select id,trainningTitle,trainningItemLevel from trainningitemhpo where id_TrainnerInfoPO='"+sqlTrainnerId+"' and trainningTitle='"+sqlTrainningTitle+"' and id<='"+tmpExerciseIdInfo.exerciseId+"' limit 10 " ;

                rs=st.executeQuery(str);

                String idList="";
                while (rs.next()){
                    idList=idList+",'"+rs.getString("id")+"'";
                }
                if (idList.length()>0)
                    idList=idList.substring(1,idList.length());

                str="select trainningTitle,a.trainningItemLevel,b.whichPartIndex as section,b.perTestTopicResultState as actionResult,b.id_BaseTrainningItemPO as exerciseId from trainningitemhpo a,trainningitemhtesttopicresultpo b where a.id=b.id_BaseTrainningItemPO and a.id in ("+idList+") order by b.id_BaseTrainningItemPO " ;

                rs=st.executeQuery(str);

                int a,b;
                int allSection=0,allOkSection=0;
                int allSection_1=0,allSection_2=0,allSection_3=0;
                int allOkSection_1=0,allOkSection_2=0,allOkSection_3=0;
                while (rs.next()){
                    a=rs.getInt("section");
                    b=rs.getInt("actionResult");
                    allSection++;
                    if (b==ElfiiCommonConstant.React_Ok_HIJ)
                        allOkSection++;
                    if (a==ElfiiCommonConstant.Section_1){
                        allSection_1++;
                        if (b==ElfiiCommonConstant.React_Ok_HIJ)
                            allOkSection_1++;
                    }
                    if (a==ElfiiCommonConstant.Section_2){
                        allSection_2++;
                        if (b==ElfiiCommonConstant.React_Ok_HIJ)
                            allOkSection_2++;
                    }
                    if (a==ElfiiCommonConstant.Section_3){
                        allSection_3++;
                        if (b==ElfiiCommonConstant.React_Ok_HIJ)
                            allOkSection_3++;
                    }
                }

                //System.out.println("======sec_1 "+allOkSection_1+"  "+allSection_1);

                str="0.0";
                if (allOkSection>0){
                    double d=100.0*allOkSection/allSection;
                    str=""+(d+0.05);
                    if (str.length()-str.indexOf(".")>1)
                        str=str.substring(0,str.indexOf(".")+2);
                }
                tmpExerciseIdInfo.allAvg=str+"%";

                str="0.0";
                if (allOkSection_1>0){
                    double d=100.0*allOkSection_1/allSection_1;
                    str=""+(d+0.05);
                    if (str.length()-str.indexOf(".")>1)
                        str=str.substring(0,str.indexOf(".")+2);
                }
                tmpExerciseIdInfo.allAvgSection_1=str+"%";

                str="0.0";
                if (allOkSection_2>0){
                    double d=100.0*allOkSection_2/allSection_2;
                    str=""+(d+0.05);
                    if (str.length()-str.indexOf(".")>1)
                        str=str.substring(0,str.indexOf(".")+2);
                }
                tmpExerciseIdInfo.allAvgSection_2=str+"%";

                str="0.0";
                if (allOkSection_3>0){
                    double d=100.0*allOkSection_3/allSection_3;
                    str=""+(d+0.05);
                    if (str.length()-str.indexOf(".")>1)
                        str=str.substring(0,str.indexOf(".")+2);
                }
                tmpExerciseIdInfo.allAvgSection_3=str+"%";
            }

            long endTimeMillis=System.currentTimeMillis();
            //System.out.println("历史查询训练成绩OK，Time:(1/1000) "+(endTimeMillis-startTimeMillis));
        } catch (Exception e) {System.out.print("ElfiiCommonhistoryItem.calcHistoryData() "+e+" "+str);}
    }

    public void calcHistoryData_K(){
        Statement st ;
        ResultSet rs ;
        String str="";
        exerciseTopics = new java.util.Vector <ElfiiCommonTypeTopic>();    
        exerciseIdInfoList = new java.util.ArrayList<ExerciseIdInfo>() ; 
        viewExerciseIdIndex=0;
        try {
            long startTimeMillis=System.currentTimeMillis();
            st = runInfo.getStatement1();

            str="select trainningTitle,a.trainningItemLevel,a.trainningDate,a.trainningTime,b.result_id as exerciseId, allTestTopicResultState as actionResult ,whichPartIndex as section from trainingresultkpo a,onetesttopicresultkpo b where a.id=b.result_id and a.id_TrainnerInfoPO='"+sqlTrainnerId+"' and trainningDate>='"+sqlStartDateHIJ+"' and trainningDate<='"+sqlEndDateHIJ+"' and trainningTitle='"+sqlTrainningTitle+"' order by b.result_id desc,whichPartIndex,b.id " ;

            rs=st.executeQuery(str);

            String idStr,titleStr,numberStr;
            ElfiiCommonTypeTopic tmpTopic;
            String tmpId="-1";
            ExerciseIdInfo tmpExerciseIdInfo;
            while(rs.next()){
                tmpTopic=new ElfiiCommonTypeTopic();
                tmpTopic.exerciseId=rs.getString("exerciseId");
                tmpTopic.actionResult=rs.getInt("actionResult");
                tmpTopic.section=rs.getInt("section");
                if (tmpTopic.actionResult==ElfiiCommonConstant.React_Ok_K)
                    tmpTopic.actionResult=ElfiiCommonConstant.React_Ok;
                else
                    tmpTopic.actionResult=ElfiiCommonConstant.React_Wrong;
                exerciseTopics.add(tmpTopic); 
                if (tmpId.equals(tmpTopic.exerciseId)==false) {
                    tmpId=tmpTopic.exerciseId;
                    tmpExerciseIdInfo = new ExerciseIdInfo();
                    tmpExerciseIdInfo.trainningTitle=rs.getString("trainningTitle");
                    tmpExerciseIdInfo.trainningItemLevel=rs.getInt("trainningItemLevel");
                    tmpExerciseIdInfo.startDate=rs.getString("trainningDate");
                    tmpExerciseIdInfo.startTime=rs.getString("trainningTime");
                    tmpExerciseIdInfo.exerciseId=tmpId;
                    exerciseIdInfoList.add(tmpExerciseIdInfo); 
                }
            }

            for (int i=0; i<exerciseIdInfoList.size(); i++){
                tmpExerciseIdInfo=(ExerciseIdInfo)exerciseIdInfoList.get(i);
                //System.out.println("======"+tmpExerciseIdInfo.trainningTitle); 
                //System.out.println("======"+tmpExerciseIdInfo.exerciseId); 

                str="select id,trainningTitle,trainningItemLevel from trainingresultkpo where id_TrainnerInfoPO='"+sqlTrainnerId+"' and trainningTitle='"+sqlTrainningTitle+"' and id<='"+tmpExerciseIdInfo.exerciseId+"' limit 10 " ;

                rs=st.executeQuery(str);

                String idList="";
                while (rs.next()){
                    idList=idList+",'"+rs.getString("id")+"'";
                }
                if (idList.length()>0)
                    idList=idList.substring(1,idList.length());

                str="select trainningTitle,a.trainningItemLevel,b.whichPartIndex as section,b.allTestTopicResultState as actionResult,b.result_id as exerciseId from trainingresultkpo a,onetesttopicresultkpo b where a.id=b.result_id and a.id in ("+idList+") order by b.result_id " ;

                rs=st.executeQuery(str);

                int a,b;
                int allSection=0,allOkSection=0;
                int allSection_1=0,allSection_2=0,allSection_3=0;
                int allOkSection_1=0,allOkSection_2=0,allOkSection_3=0;
                while (rs.next()){
                    a=rs.getInt("section");
                    b=rs.getInt("actionResult");
                    allSection++;
                    if (b==ElfiiCommonConstant.React_Ok_K)
                        allOkSection++;
                    if (a==ElfiiCommonConstant.Section_1){
                        allSection_1++;
                        if (b==ElfiiCommonConstant.React_Ok_K)
                            allOkSection_1++;
                    }
                    if (a==ElfiiCommonConstant.Section_2){
                        allSection_2++;
                        if (b==ElfiiCommonConstant.React_Ok_K)
                            allOkSection_2++;
                    }
                    if (a==ElfiiCommonConstant.Section_3){
                        allSection_3++;
                        if (b==ElfiiCommonConstant.React_Ok_K)
                            allOkSection_3++;
                    }
                }

                //System.out.println("======sec_1 "+allOkSection_1+"  "+allSection_1);

                str="0.0";
                if (allOkSection>0){
                    double d=100.0*allOkSection/allSection;
                    str=""+(d+0.05);
                    if (str.length()-str.indexOf(".")>1)
                        str=str.substring(0,str.indexOf(".")+2);
                }
                tmpExerciseIdInfo.allAvg=str+"%";

                str="0.0";
                if (allOkSection_1>0){
                    double d=100.0*allOkSection_1/allSection_1;
                    str=""+(d+0.05);
                    if (str.length()-str.indexOf(".")>1)
                        str=str.substring(0,str.indexOf(".")+2);
                }
                tmpExerciseIdInfo.allAvgSection_1=str+"%";

                str="0.0";
                if (allOkSection_2>0){
                    double d=100.0*allOkSection_2/allSection_2;
                    str=""+(d+0.05);
                    if (str.length()-str.indexOf(".")>1)
                        str=str.substring(0,str.indexOf(".")+2);
                }
                tmpExerciseIdInfo.allAvgSection_2=str+"%";

                str="0.0";
                if (allOkSection_3>0){
                    double d=100.0*allOkSection_3/allSection_3;
                    str=""+(d+0.05);
                    if (str.length()-str.indexOf(".")>1)
                        str=str.substring(0,str.indexOf(".")+2);
                }
                tmpExerciseIdInfo.allAvgSection_3=str+"%";
            }

            long endTimeMillis=System.currentTimeMillis();
            //System.out.println("历史查询训练成绩OK，Time:(1/1000) "+(endTimeMillis-startTimeMillis));
        } catch (Exception e) {System.out.print("ElfiiCommonhistoryItem.calcHistoryData() "+e+" "+str);}
    }

    public void calcHistoryData_L(){
        Statement st,st2 ;
        ResultSet rs,rs2 ;
        String str="";
        exerciseTopics = new java.util.Vector <ElfiiCommonTypeTopic>();    
        exerciseIdInfoList = new java.util.ArrayList<ExerciseIdInfo>() ; 
        viewExerciseIdIndex=0;
        try {
            long startTimeMillis=System.currentTimeMillis();
            st = runInfo.getStatement1();
            st2= runInfo.getStatement2();

            str="select a.id,trainningTitle,trainningItemLevel,trainningDate,trainningTime,capturedTrainningResultImage,testAllCompletedPastRate as completedRate,testAllCorrectRate as correctRate from trainningitemlpo a,trainningitemlglobaltrainingresultpo b where a.id=b.id_BaseTrainningItemPO and id_TrainnerInfoPO='"+sqlTrainnerId+"' and trainningDate>='"+sqlStartDateHIJ+"' and trainningDate<='"+sqlEndDateHIJ+"' and trainningTitle='"+sqlTrainningTitle+"' order by id desc" ;

            rs=st.executeQuery(str);

            String idStr,titleStr,numberStr,tmpStr;
            ExerciseIdInfo tmpExerciseIdInfo;
            while(rs.next()){
                tmpExerciseIdInfo = new ExerciseIdInfo();
                tmpExerciseIdInfo.trainningTitle=rs.getString("trainningTitle");
                tmpExerciseIdInfo.trainningItemLevel=rs.getInt("trainningItemLevel");
                tmpExerciseIdInfo.startDate=rs.getString("trainningDate");
                tmpExerciseIdInfo.startTime=rs.getString("trainningTime");
                tmpExerciseIdInfo.exerciseId=rs.getString("id");
                tmpExerciseIdInfo.correctRate=rs.getInt("correctRate");
                tmpExerciseIdInfo.completedRate=rs.getInt("completedRate");
                tmpExerciseIdInfo.exerciseId=rs.getString("id");
                File file = new File("tmp_history_capturedTrainningResultImage.png");       
                FileOutputStream fos = new java.io.FileOutputStream(file);
                InputStream is = rs.getBinaryStream("capturedTrainningResultImage");
                byte[] b = new byte[10240];
                int readNumb;
                while((readNumb=is.read(b,0,10240)) != -1){
                    fos.write(b,0,readNumb);
                }
                fos.flush();
                tmpExerciseIdInfo.capturedTrainningResultImage=ImageIO.read(file);

                tmpStr=tmpExerciseIdInfo.exerciseId;
                
                if (tmpStr.length()>10)
                    tmpStr="'"+tmpStr+"'";  //-如果大于10，说明数据库是字符型的ID

                str="select avg(testAllCompletedPastRate) as historyCompletedRate,avg(testAllCorrectRate) as historyCorrectRate from trainningitemlpo a,trainningitemlglobaltrainingresultpo b where a.id=b.id_BaseTrainningItemPO and id_TrainnerInfoPO='"+sqlTrainnerId+"'  " ;
                rs2=st2.executeQuery(str);
                if (rs2.next()){
                    tmpExerciseIdInfo.historyCompletedRate=(int)(rs2.getDouble("historyCompletedRate"));
                    tmpExerciseIdInfo.historyCorrectRate=(int)(rs2.getDouble("historyCorrectRate"));
                }

                exerciseIdInfoList.add(tmpExerciseIdInfo); 
            }

            long endTimeMillis=System.currentTimeMillis();
            //System.out.println("历史查询训练成绩OK，Time:(1/1000) "+(endTimeMillis-startTimeMillis));
        } catch (Exception e) {System.out.print("ElfiiCommonhistoryItem.calcHistoryData() "+e+" "+str);}
    }

    public void calcHistoryData_M(){
        Statement st ;
        ResultSet rs ;
        String str="";
        exerciseTopics = new java.util.Vector <ElfiiCommonTypeTopic>();    
        exerciseIdInfoList = new java.util.ArrayList<ExerciseIdInfo>() ; 
        viewExerciseIdIndex=0;
        try {
            long startTimeMillis=System.currentTimeMillis();
            st = runInfo.getStatement1();

            str="select id,trainningTitle,trainningItemLevel,trainningDate,trainningTime,capturedTrainningResultImage from trainningitemmpo where id_TrainnerInfoPO='"+sqlTrainnerId+"' and trainningDate>='"+sqlStartDateHIJ+"' and trainningDate<='"+sqlEndDateHIJ+"' and trainningTitle='"+sqlTrainningTitle+"' order by id desc" ;

            rs=st.executeQuery(str);

            String idStr,titleStr,numberStr;
            ExerciseIdInfo tmpExerciseIdInfo;
            while(rs.next()){
                tmpExerciseIdInfo = new ExerciseIdInfo();
                tmpExerciseIdInfo.trainningTitle=rs.getString("trainningTitle");
                tmpExerciseIdInfo.trainningItemLevel=rs.getInt("trainningItemLevel");
                tmpExerciseIdInfo.startDate=rs.getString("trainningDate");
                tmpExerciseIdInfo.startTime=rs.getString("trainningTime");
                tmpExerciseIdInfo.exerciseId=rs.getString("id");
                File file = new File("tmp_history_capturedTrainningResultImage.png");       
                FileOutputStream fos = new java.io.FileOutputStream(file);
                InputStream is = rs.getBinaryStream("capturedTrainningResultImage");
                byte[] b = new byte[10240];
                int readNumb;
                while((readNumb=is.read(b,0,10240)) != -1){
                    fos.write(b,0,readNumb);
                }
                fos.flush();
                tmpExerciseIdInfo.capturedTrainningResultImage=ImageIO.read(file);
                exerciseIdInfoList.add(tmpExerciseIdInfo); 
            }

            long endTimeMillis=System.currentTimeMillis();
            //System.out.println("历史查询训练成绩OK，Time:(1/1000) "+(endTimeMillis-startTimeMillis));
        } catch (Exception e) {System.out.print("ElfiiCommonhistoryItem.calcHistoryData() "+e+" "+str);}
    }
    public void calcHistoryData_N(){
        Statement st ;
        ResultSet rs ;
        String str="";
        exerciseTopics = new java.util.Vector <ElfiiCommonTypeTopic>();    
        exerciseIdInfoList = new java.util.ArrayList<ExerciseIdInfo>() ; 
        viewExerciseIdIndex=0;
        try {
            long startTimeMillis=System.currentTimeMillis();
            st = runInfo.getStatement1();

            str="select id,trainningTitle,trainningItemLevel,trainningDate,trainningTime,capturedTrainningResultImage from trainningitemnpo where id_TrainnerInfoPO='"+sqlTrainnerId+"' and trainningDate>='"+sqlStartDateHIJ+"' and trainningDate<='"+sqlEndDateHIJ+"' and trainningTitle='"+sqlTrainningTitle+"' order by id desc" ;

            rs=st.executeQuery(str);

            String idStr,titleStr,numberStr;
            ExerciseIdInfo tmpExerciseIdInfo;
            while(rs.next()){
                tmpExerciseIdInfo = new ExerciseIdInfo();
                tmpExerciseIdInfo.trainningTitle=rs.getString("trainningTitle");
                tmpExerciseIdInfo.trainningItemLevel=rs.getInt("trainningItemLevel");
                tmpExerciseIdInfo.startDate=rs.getString("trainningDate");
                tmpExerciseIdInfo.startTime=rs.getString("trainningTime");
                tmpExerciseIdInfo.exerciseId=rs.getString("id");
                File file = new File("tmp_history_capturedTrainningResultImage.png");       
                FileOutputStream fos = new java.io.FileOutputStream(file);
                InputStream is = rs.getBinaryStream("capturedTrainningResultImage");
                byte[] b = new byte[10240];
                int readNumb;
                while((readNumb=is.read(b,0,10240)) != -1){
                    fos.write(b,0,readNumb);
                }
                fos.flush();
                tmpExerciseIdInfo.capturedTrainningResultImage=ImageIO.read(file);
                exerciseIdInfoList.add(tmpExerciseIdInfo); 
            }

            long endTimeMillis=System.currentTimeMillis();
            //System.out.println("历史查询训练成绩OK，Time:(1/1000) "+(endTimeMillis-startTimeMillis));
        } catch (Exception e) {System.out.print("ElfiiCommonhistoryItem.calcHistoryData() "+e+" "+str);}
    }


    public void calcHistoryData(){

        sqlStartDateHIJ=sqlStartDate.substring(0,4)+"-"+sqlStartDate.substring(4,6)+"-"+sqlStartDate.substring(6,8);
        sqlEndDateHIJ=sqlEndDate.substring(0,4)+"-"+sqlEndDate.substring(4,6)+"-"+sqlEndDate.substring(6,8);

        isTrainingD = false;
        
        if (sqlTrainningTitle.startsWith("A") || sqlTrainningTitle.startsWith("B") || sqlTrainningTitle.startsWith("C"))
            calcHistoryData_ABC();
        if( sqlTrainningTitle.startsWith("D")){//训练D将视觉和听觉部分的结果分开，为两页显示，但在数据表中为显示两组数据，故要特殊处理
        	isTrainingD = true;
        	calcHistoryData_D();
        }
        if (sqlTrainningTitle.startsWith("F") || sqlTrainningTitle.startsWith("G"))
            calcHistoryData_FG();
        if (sqlTrainningTitle.startsWith("H") || sqlTrainningTitle.startsWith("I") || sqlTrainningTitle.startsWith("J") )
            calcHistoryData_HIJ();
        if (sqlTrainningTitle.startsWith("K") )
            calcHistoryData_K();
        if (sqlTrainningTitle.startsWith("L") )
            calcHistoryData_L();
        if (sqlTrainningTitle.startsWith("M") )
            calcHistoryData_M();
        if (sqlTrainningTitle.startsWith("N") )
            calcHistoryData_N();

    }

}
